home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Common.h
-
- Copyright: © 1997-1998 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef __PRINTING__
- #include <Printing.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __QDOFFSCREEN__
- #include <QDOffscreen.h>
- #endif
-
- #ifndef __NAVIGATION__
- #include "Navigation.h"
- #endif
-
- #ifndef Common_Defs
- #define Common_Defs
-
- #define kStr255Len 255 // this length is for NewPtr call, used before making a Toolbox call
- #define kNameLen 32 // file name length
-
- enum checkboxstate { dechecked,checked };
-
- #define kStrangeErr -1
-
- #define kActive 0
- #define kInactive 255
-
- // ASCII key characters
- #define kCrChar 13 // carriage return key
- #define kDelChar 8 // delete key
- #define kEnterChar 3 // enter char
- #define kPeriodChar 46 // period char
- #define kTabKey 9 // tab char
- #define kYKey 121
- #define kNKey 110
- #define kEscKey 27
- #define kColon 58
- #define kZero 48
- #define kNine 57
-
- #define dOK 1
- #define dCancel 2
-
- #define kDelayTick 10 // ticks for button hiliting
- #define kWindowWidth 500 // width size for the text window
-
- #define kMaxDocumentCount 100 // maximum number of documents allowed
-
- #define InitialH 16
- #define InitialV 42
-
- #define TopMargin 6
- #define LeftMargin 6
- #define RightMargin 6
- #define BottomMargin 6
-
- #define ScrollResolution 12
-
- #define kOpenRsrcID 300
- #define kOpenRsrcID2 301
-
- // file constants
- #define kFileCreator 'CPAP'
- #define kFileType 'TEXT'
- #define kFileTypePICT 'PICT'
- #define kOpenRsrcType 'open'
-
- // resource constants
- #define rIconSuite 128
-
- #define iIconSuite 3
-
- // alert resources constants:
- #define rSaveChangesID 128
- #define rRevertID 129
- #define rGenericAlertID 130
- #define rAboutID 131
-
- // resource string constants
- #define rAppStringsID 128
- enum {
- sApplicationName = 1,
- sTranslationLockedErr,
- sTranslationErr,
- sOpeningErr,
- sReadErr, // 5
- sWriteToBusyFileErr,
- sBusyOpen,
- sChooseFile,
- sChooseFolder,
- sChooseVolume, // 10
- sCreateFolder,
- sChooseObject,
- sSaveCopyMessage,
- slSavePromptIndex,
- slClosingIndex, // 15
- slQuittingIndex,
- sAddRemoveTitle,
- sLowMemoryErr
- };
-
- #define MenuStringsID 129
- enum {
- slCantUndo = 1,
- slUndoDrag,
- slRedoDrag
- };
-
- // menu resource constants
- #define MenuBarID 128
-
- #define idAppleMenu 128
- #define AboutItem 1
-
- #define idFileMenu 129
- #define NewItem 1
- #define OpenItem 2
- #define CloseItem 4
- #define SaveItem 5
- #define SaveACopyItem 6
- #define RevertItem 7
- //=
- #define DictionaryItem 9
- //=
- #define PageSetupItem 11
- #define PrintItem 12
- //=
- #define QuitItem 14
-
- #define idEditMenu 130
- #define iUndo 1
- #define iCut 3
- #define iCopy 4
- #define iPaste 5
- #define iClear 6
- #define iSelectAll 7
-
- #define idUtilsMenu 131
- #define iSelectDir 1
- #define iSelectVol 2
- #define iSelectObject 3
- #define iCreateFolder 5
- #define iCustomOpen 7
- #define iAddFiles 8
-
- #define kScrollBarWidth 16
- #define kScrollBarPos kScrollBarWidth-1
-
- // main document:
- typedef struct Document
- {
- WindowPtr theWindow;
- TEHandle theTE;
- short docTop;
- RgnHandle hiliteRgn;
-
- ControlHandle vScroll;
- ControlHandle hScroll;
- short vScrollPos;
-
- short fRefNum;
- short dirty;
-
- Handle undoDragText;
- short undoSelStart;
- short undoSelEnd;
-
- short lastSelStart;
- short lastSelEnd;
-
- ParamBlockRec fioParamBlock; // param block for file I/O operations
- Handle fPict;
- Handle fHeader;
- long fPictLength;
-
- } Document;
-
-
- // offscreen drawing:
- typedef struct WindowOffscreen
- {
- CGrafPtr windowPort;
- GDHandle windowDevice;
- GWorldPtr offscreenWorld;
- } WindowOffscreen;
-
- WindowOffscreen* DrawOffscreen(WindowPtr theWindow);
-
-
- #define mBarHeight (short *)0x0BAA // Low mem global for menu bar
- #define EventQueue (QHdrPtr)0x14A // Event queue header (10 bytes)
- #define Mouse ((Point*)0x830) // processed mouse
- #define KeyTime (long*)0x186 // tickcount when KEYLAST was rec'd
-
- #define TopLeft(aRect) (* (Point *) &(aRect).top)
- #define BotRight(aRect) (* (Point *) &(aRect).bottom)
-
- #define RectWidth(aRect) ((aRect).right - (aRect).left)
- #define RectHeight(aRect) ((aRect).bottom - (aRect).top)
-
- #define Max(X, Y) ( ((X)>(Y)) ? (X) : (Y) )
- #define Min(X, Y) ( ((X)>(Y)) ? (Y) : (X) )
-
- #define Pin(VALUE, MIN, MAX) ( ((VALUE) < (MIN)) ? (MIN) : ( ((VALUE) > (MAX)) ? (MAX) : (VALUE) ) )
-
- #define kOpenPrefKey 1
- #define kSavePrefKey 2
- #define kSelectFilePrefKey 3
- #define kSelectFolderPrefKey 4
- #define kSelectVolumePrefKey 5
- #define kNewFolderPrefKey 6
- #define kSelectObjectPrefKey 7
-
- //**************************************************************
-
- // utility routines for detecting keydowns
- Boolean ModifierDown(short modifier);
- Boolean OptionDown(void);
- Boolean ShiftDown(void);
- Boolean CommandDown(void);
- Boolean ControlDown(void);
-
- static SInt16 rnd(SInt16 max);
- short RandTween(short low, short high);
-
- // file utilities:
- OSErr PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName, short maxPathLength, short full);
- Boolean FSSpecsEq(FSSpec* a, FSSpec* b);
- pascal void myEventProc(NavEventCallbackMessage callBackSelctor, NavCBRecPtr callBackParms, NavCallBackUserData callBackUD);
-
- // dialog control utilities
- void hiliteTheButton(DialogPtr theDialog, short whichItem);
- void AdornButton(DialogPtr theDialog, short whichItem);
- unsigned char* GetItemStr(DialogPtr theDialog, short theItem, unsigned char* theString);
- void PokeItemStr(DialogPtr theDialog, short theItem, unsigned char* theString);
- void PokeCtlVal(DialogPtr theDialog, short theItem, short value);
- void PokeCtlHilite(DialogPtr theDialog, short theItem, short value);
-
- // string utilities
- OSType Str2OSType(Str255 theStr);
- long MyStrLen(char* s);
- long myStringToLong(char* s);
- short myStringToShort(char* s);
- void myStrCpy(char* dst, char* src);
- void myStrCat(char* dst, char* src);
- unsigned char* ConcatPP(unsigned char* a,unsigned char* b);
- char* MyP2CCopy(unsigned char* psrc,char* ctarget);
- unsigned char* MyC2PStr(char* theStr);
- char* MyP2CStr(unsigned char* theStr);
-
- void DrawIconSuite(short resID, Rect destRect);
- void DebugCStr(char* msg);
- void AdjustCursor(Point theLoc, RgnHandle theRgn);
-
-
- // *******************************************************************
-
- // prototypes for 'document.c'
- Document* NewDocument(Boolean newAsPICT);
- Document* IsDocumentWindow(WindowPtr theWindow);
- void DoUndoDrag(void);
- pascal void DocumentClickLoop(void);
- void DoActivateDocument(Document* theDocument, short activate);
- void DoSelectAllDocument(Document* theDocument);
- void UpdateWindow(Document* theDocument);
- void GrowDocumentWindow(WindowPtr theWindow, Point thePoint);
- void DoZoomDocument(Document* theDocument, WindowPtr theWindow, short thePart);
- pascal void ScrollProc(ControlHandle theControl, short theCode);
- void DocumentHighlightProc(void);
- void SizeDocWindow(Document* theDocument);
-
- // prototypes for 'files.c'
- short DoSaveDocument(Document* theDocument);
- void DoNewDocument(Boolean newDocAsPICT);
- OSErr DoOpenFile(FSSpec* theFile, Boolean openAsPICT);
-
- OSErr DoOpenDocument(void);
- OSErr DoOpenDocumentTheOldWay(void);
-
- OSErr SaveACopyDocument(Document* theDocument);
- OSErr SaveACopyDocumentTheOldWay(Document* theDocument);
-
- void DoRevertDocument(Document* theDocument);
- void DoRevertDocumentTheOldWay(Document* theDocument);
-
- // prototypes for 'Utilities.c'
- short TEIsFrontOfLine(short offset, TEHandle theTE);
- short TEGetLine(short offset, TEHandle theTE);
- short myTECut(TEHandle theTE);
- short myTEPaste(TEHandle theTE, short* spaceBefore, short* spaceAfter);
-
- // prototypes for 'Offscreen.c'
- void DrawOnscreen(WindowOffscreen* theOffscreen);
-
- // prototypes for 'document.c'
- void AdjustDocumentView(Document* theDocument);
- void AdjustScrollBar(Document* theDocument);
- void CloseDocument(Document* theDocument, Boolean quitting);
- void DisableUndoDrag(void);
- void AddText(Document* theDocument, Ptr text, long len);
-
- // prototypes for 'drag.c'
- short DragText(Document* theDocument, EventRecord* theEvent, RgnHandle hiliteRgn);
-
- // prototypes for 'menu.c'
- void AdjustMenus(void);
- void DoMenuCommand(long select);
-
- // prototypes for 'event.c'
- void EventLoop(void);
- pascal OSErr MyHandleOAPP(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
- pascal OSErr MyHandleODOC(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
- pascal OSErr MyHandleQUIT(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
-
- OSErr AEGetDescData(const AEDesc* desc, DescType* typeCode, void* dataBuffer, ByteCount maximumSize, ByteCount* actualSize);
-
- void DoLowMemAlert( void );
-
- #endif // Common_Defs